from rest_framework.authentication import BaseAuthentication
import auth01.models as models
from rest_framework import exceptions

class Authentication(BaseAuthentication):

    def authenticate(self, request):
        token =request._request.GET.get("token")
        token_obj=models.UserToken.objects.filter(token=token).first()
        for x in models.UserToken.objects.all():
            print(x.token)
        print(token,token_obj)
        if not token_obj:
            raise exceptions.AuthenticationFailed("用户验证失败")

        return (token_obj.user,token_obj)

    def authenticate_header(self, request):
        pass